package Song.Han.day04.demo05;

import java.util.ArrayList;
import java.util.Random;

/*
* 题目：
*   用一个大集合存放20个随机数，将其中的偶数筛选出来，放入小集合中
* */
public class Demo03ArrayListReturn {
    public static void main(String[] args) {

        ArrayList<Integer> bigList = new ArrayList<>();

        Random r = new Random();

        for (int i = 0; i < 20; i++) {
            int num = r.nextInt(100);
            bigList.add(num);
        }

        ArrayList<Integer> smallList = getSmallList(bigList);

        for (int i = 0; i < bigList.size(); i++) {
            System.out.print(bigList.get(i)+" ");
        }
        System.out.println();
        System.out.println("偶数有："+smallList.size()+"个");
        for (int i = 0; i < smallList.size(); i++) {
            System.out.print(smallList.get(i)+" ");
        }

    }

    public static ArrayList<Integer> getSmallList(ArrayList<Integer> bigList){
        ArrayList<Integer> smallList = new ArrayList<>();

        for (int i = 0; i < 20; i++) {
            int num = bigList.get(i);
            if ( num % 2 == 0) {
                smallList.add(num);
            }
        }
        return smallList;
    }
}
